<?php

namespace app\admin\model;

use think\Model;
use traits\model\SoftDelete;

class GoodsDonate extends Model
{

    use SoftDelete;

    

    // 表名
//    protected $name = 'goods';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'int';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = 'updatetime';
    protected $deleteTime = 'deletetime';

    // 追加属性
    protected $append = [
//        'goods_attr_text',
//        'is_ship_text',
//        'freight_type_text',
//        'is_recommond_text',
//        'status_text',
//        'state_text',
//        'is_good_text',
//        'is_checking_text',
//        'checktime_text'
    ];
    

    
    public function getGoodsAttrList()
    {
        return ['0' => __('Goods_attr 0'), '1' => __('Goods_attr 1'), '2' => __('Goods_attr 2')];
    }

    public function getIsShipList()
    {
        return ['0' => __('Is_ship 0'), '1' => __('Is_ship 1')];
    }

    public function getFreightTypeList()
    {
        return ['0' => __('Freight_type 0'), '1' => __('Freight_type 1')];
    }

    public function getIsRecommondList()
    {
        return ['0' => __('Is_recommond 0'), '1' => __('Is_recommond 1')];
    }

    public function getStatusList()
    {
        return ['0' => __('Status 0'), '1' => __('Status 1'), '2' => __('Status 2')];
    }

    public function getStateList()
    {
        return ['0' => __('State 0'), '1' => __('State 1'), '2' => __('State 2')];
    }

    public function getTypeList()
    {
        return ['0' => __('正常商品'), '1' => __('预约商品'), '2' => __('预售商品'), '3' => __('爆品')];
    }

    public function getIsGoodList()
    {
        return ['1' => __('Is_good 1'), '2' => __('Is_good 2')];
    }

    public function getIsCheckingList()
    {
        return ['1' => __('Is_checking 1'), '2' => __('Is_checking 2')];
    }


    public function getGoodsAttrTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['goods_attr']) ? $data['goods_attr'] : '');
        $list = $this->getGoodsAttrList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getIsShipTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['is_ship']) ? $data['is_ship'] : '');
        $list = $this->getIsShipList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getFreightTypeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['freight_type']) ? $data['freight_type'] : '');
        $list = $this->getFreightTypeList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getIsRecommondTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['is_recommond']) ? $data['is_recommond'] : '');
        $list = $this->getIsRecommondList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getStatusTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['status']) ? $data['status'] : '');
        $list = $this->getStatusList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getStateTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['state']) ? $data['state'] : '');
        $list = $this->getStateList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getIsGoodTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['is_good']) ? $data['is_good'] : '');
        $list = $this->getIsGoodList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getIsCheckingTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['is_checking']) ? $data['is_checking'] : '');
        $list = $this->getIsCheckingList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getChecktimeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['checktime']) ? $data['checktime'] : '');
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }

    protected function setChecktimeAttr($value)
    {
        return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
    }


    public function goodscategory()
    {
        return $this->belongsTo('GoodsCategory', 'cid1', 'id', [], 'LEFT')->setEagerlyType(0);
    }




    public function category1()
    {
        return $this->belongsTo('GoodsCategory', 'cid1', 'id', [], 'LEFT')->setEagerlyType(0);
    }

    public function category2(){
        return $this->belongsTo('GoodsCategory', 'cid2', 'id', [], 'LEFT')->setEagerlyType(0);
    }

    public function category3(){
        return $this->belongsTo('GoodsCategory', 'category_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }
    public function admin()
    {
        return $this->belongsTo('Admin', 'shop_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }
    public function shopapply()
    {
        return $this->hasOne('ShopApply', 'id', 'shop_id', [], 'LEFT')->setEagerlyType(0);
    }
    public function user()
    {
        return $this->belongsTo('User', 'uid', 'id', [], 'LEFT')->setEagerlyType(0);
    }
}
